/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datacoletor;

import filesJavacc.Adder;
import filesJavacc.AdderMain;
import filesJavacc.ParseException;
import filesJavacc.TokenMgrError;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Heitor
 */
public class Extractor {
    
    String path = "C:/Users/Heitor/nwconsoleOut_TECAM2.txt";
    String text;
    
    public Extractor(){
        try {
            open();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Extractor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Extractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public Extractor(String path) {        
        this.path = path;

        try {
            open();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Extractor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Extractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void open() throws FileNotFoundException, IOException, IOException {
        InputStream input = new FileInputStream(path);

        StringBuilder sb = new StringBuilder();
        String line;
        String line_aux = "";
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        while ((line = reader.readLine()) != null) {
            if(line.equals("> ")){
                sb.append("/&/").append(line).append("/a2/").append("\n");
            } else if(line.equals("^C")) {
                sb.append("/a2/").append(line).append("/&/").append("\n");
            } else {
                sb.append(line).append("\n");
            }
            line_aux = line;
        }
        input.close();
        text = sb.toString();

    }
    
    public void printText() {
        System.out.println("Texto \n\n" + text + "\n\n");
    }
    
    public void statrGenerator() throws TokenMgrError, FileNotFoundException, IOException, ParseException {

        GeneratorGraphs generator = new GeneratorGraphs(text);
        generator.start();    
    }

    public void analysis() throws TokenMgrError, FileNotFoundException, IOException {
        try {
            Adder ad = new Adder(text);
//            ad.showCliSessions();
//            ad.showFrame();
//            ad.showGw();
            ad.showMote();
//            ad.showMsg();
//            ad.showMsgV();
//            ad.showOptim();
//            ad.showSessions();
            ad.showStatCur();
            ad.showStatNet();
            ad.showStatDay();
            ad.showStatLife();
            ad.showStatShort();
//            ad.showStatus();
//            ad.showTime();
//            ad.showVer();
//            
//            ad.getAcls();
//            ad.getAlarms();
//            ad.getBlacklist();
//            ad.getNetwork();
//            ad.getPaths();
//            ad.getRedundancy();
//            ad.getSecurity();
//            ad.getSla();
//            ad.getSystem();
//            ad.getUsers();

            System.out.println("Show:\n" + ad.getsCliSessionsList().toString() + "\n "+ 
                    ad.getsFrameList().toString() + "\n "+ 
                    ad.getsGwList().toString()  + "\n "+ 
                    ad.getsMoteList().toString()  + "\n "+ 
                    ad.getsMsgList().toString()  + "\n "+ 
                    ad.getsMsgVList().toString()  + "\n "+ 
                    ad.getsOptimList().toString()  + "\n "+ 
                    ad.getsSessionsList().toString()  + "\n "+ 
                    ad.getsStatCurList().toString()  + "\n "+ 
                    ad.getsStatDayList().toString()  + "\n "+ 
                    ad.getsStatLifeList().toString()  + "\n "+ 
                    ad.getsStatNetList().toString()  + "\n "+ 
                    ad.getsStatShortList().toString()  + "\n "+ 
                    ad.getsStatusList().toString()  + "\n "+ 
                    ad.getsTimeList().toString()  + "\n "+ 
                    ad.getsVerList().toString()
                    );
            
            System.out.println("Get:\n" + ad.getgAclsList().toString() + "\n "+ 
                    ad.getgAlarmsList().toString() + "\n "+ 
                    ad.getgBlacklistList().toString()  + "\n "+ 
                    ad.getgNetworkList().toString()  + "\n "+ 
                    ad.getgPathsList().toString()  + "\n "+ 
                    ad.getgRedundancyList().toString()  + "\n "+ 
                    ad.getgSecurityList().toString()  + "\n "+ 
                    ad.getgSlaList().toString()  + "\n "+ 
                    ad.getgSystemList().toString()  + "\n "+ 
                    ad.getgUsersList().toString()
                    );            
        } catch (ParseException ex) {
            System.out.println("[Erro]\n" + ex.toString());
        }
    }
    
    public void analysis2(String path1) throws TokenMgrError, FileNotFoundException, IOException {
        try {
            text = "";
            this.path = path1;
            open();
            AdderMain ad = new AdderMain(text);
            ad.exec();
        } catch (ParseException ex) {
            System.out.println("[Erro!]\n" + ex.toString());
        }
    }    
    
}
